/*
 * @Author: Lizhen
 * @Date: 2023-08-17
 * @LastEditors: Lizhen
 * @LastEditTime: 2023-08-17
 * @FilePath: /vite-project/src/stores/times.js
 * @Description: 
 */
import { ref, computed } from 'vue'
import dayjs from 'dayjs'
import { defineStore } from 'pinia'

export const useTimesStore = defineStore('times', () => {
  // const timesArr = ref([
  //   {
  //     no: "2023-08-17 12:43:15",
  //     role: "2",
  //     workUp: "",
  //     noonDown: "",
  //     noonUp: "",
  //     workDown: "",
  //     canEdit: false,
  //   }
  // ])
  const setTimesArr = (value) => {
    timesArr.value = value
  }
  const handleAdd = (value) => {
    timesArr.value.push({
      no: dayjs().format('YYYY-MM-DD HH:mm:ss'),
      role: "",
      workUp: "",
      noonDown: "",
      noonUp: "",
      workDown: "",
      canEdit: true
    })
  }
  // const handleEdit = (index, value) => {
  //   timesArr.value[index] = value
  // }
  const handleDelete = (index) => {
    timesArr.value.splice(index, 1)
  }

  return {
    timesArr: ref([
      {
        no: "2023-08-17 12:43:15",
        role: "2",
        workUp: "",
        noonDown: "",
        noonUp: "",
        workDown: "",
        canEdit: false,
      }
    ]), setTimesArr, handleAdd, handleEdit(index, value) {
      timesArr.value[index] = value
    }, handleDelete  }
}, {
  persist: {
    enabled: true,
    // strategies: [
    //   {
    //     storage: localStorage, // 缓存使用方式 直接写,不带引号 localStorage sessionStorage
    //     // paths: [] // 需要缓存键
    //   },
    // ],
  }
})